package cn.iocoder.yudao.module.blog.controller.app.jiucase;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.blog.controller.admin.caselike.vo.BlogCaseLikeCreateReqVO;
import cn.iocoder.yudao.module.blog.controller.admin.postlike.vo.BlogPostLikeCreateReqVO;
import cn.iocoder.yudao.module.blog.controller.admin.postlike.vo.BlogPostLikePageReqVO;
import cn.iocoder.yudao.module.blog.controller.app.jiucase.vo.likevo.AppBlogCaseLikeListReqVO;
import cn.iocoder.yudao.module.blog.controller.app.post.likevo.AppBlogPostLikeListReqVO;
import cn.iocoder.yudao.module.blog.controller.app.post.likevo.AppBlogPostLikeRespVO;
import cn.iocoder.yudao.module.blog.convert.postlike.BlogPostLikeConvert;
import cn.iocoder.yudao.module.blog.dal.dataobject.caselike.BlogCaseLikeDO;
import cn.iocoder.yudao.module.blog.dal.dataobject.postlike.BlogPostLikeDO;
import cn.iocoder.yudao.module.blog.service.caselike.BlogCaseLikeService;
import cn.iocoder.yudao.module.blog.service.jiucase.BlogJiuCaseService;
import cn.iocoder.yudao.module.blog.service.post.BlogPostService;
import cn.iocoder.yudao.module.blog.service.postlike.BlogPostLikeService;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;

@Tag(name = "用户 APP - 案例点赞")
@RestController
@RequestMapping("/blog/case/like")
@Validated
public class AppBlogJiuCaseLikeController {
    @Resource
    private BlogCaseLikeService blogCaseLikeService;

    @Resource
    private BlogJiuCaseService blogJiuCaseService;

    @Resource
    private MemberUserApi memberUserApi;

    @PostMapping("/create")
    @Operation(summary = "点赞")
    public CommonResult<Long> createLike(@Valid @RequestBody BlogCaseLikeCreateReqVO createReqVO) {
        Long id = blogCaseLikeService.createCaseLike(createReqVO);
        blogJiuCaseService.updateCaseLikeNum(createReqVO.getCaseId(), 1);

        return success(createReqVO.getCaseId());
    }

    @PostMapping("/list")
    @Operation(summary = "获得案例点赞列表")
    public CommonResult<List<Long>> getLikeList(@Valid @RequestBody AppBlogCaseLikeListReqVO reqVO){
        List<BlogCaseLikeDO> list = blogCaseLikeService.getCaseLikeList(reqVO.getMemberId(), reqVO.getCaseList());
        return success(convertList(list, BlogCaseLikeDO::getCaseId));
    }
}
